<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Admin_model extends CI_Model {

	public function __construct()
	{
		parent::__construct();
		
	}

	public function check_username($uname)
	{
		$this->load->database();
		$sql = "SELECT username FROM admin_account WHERE username = ?";
		$query = $this->db->query($sql, array($uname));

		if ($query->num_rows() > 0)
			return true; /*Username exists.*/
		return false;
	}

	public function check_login($account)
	{
		$this->load->database();
		$sql = "SELECT username,password FROM admin_account WHERE username = ? AND password = ?"; 
		$query = $this->db->query($sql, array($account['username'], $account['password']));
		
		if($query->num_rows() == 0)
			$query = NULL;
			
		return $query;
	}

	public function getLogs() {
		$this->load->database();
		$query = $this->db->get('log');

		return $query->result_array();
	}

	public function getMessages() {
		$this->load->database();
		$this->db->where('receiver', 'admin');
		$query = $this->db->get('message');

		return $query->result_array();
	}

	public function sendMessage($to, $message) {
		$this->load->database();
		$this->db->insert('message', array(
			'sender' => 'admin',
			'receiver' => $to,
			'message' => $message
		));
	}

}

/* End of file admin_model.php */
/* Location: ./application/models/admin_model.php */